package org.longs.converter.parser;

import org.longs.bean.PalRGB;

import java.awt.*;
import java.util.stream.IntStream;

public class RepeatPixelsParser implements Parser {

    private int aByte;

    @Override
    public boolean judge(int flag) {
        aByte = flag;
        return flag >> 6 == 2;
    }

    @Override
    public void analysis(Recorder recorder, BufferedColorListener listener) {
        recorder.setFlag("RepeatPixels");
        PalRGB color = recorder.getPalRGBs()[recorder.getBytes()[recorder.getOffsetUp()] & 0xFF];
        IntStream.range(0, (aByte & 63))
                .forEach(i -> listener.result(new Color(color.getR(), color.getG(), color.getB(), 255), recorder));
    }

}
